package com.zxy.health.controller;


import com.zxy.health.dao.TeacherDao;
import com.zxy.health.service.TeacherService;
import com.zxy.health.utils.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    @RequestMapping("/toTeacher")
    public String toTeacher(){
        return "teacher";
    }

    @RequestMapping("/addTeacher")
    @ResponseBody
    public String addTeacher(
            @Param("name") String name,
            @Param("sex")Integer sex,
            @Param("username")String username,
            @Param("password")String password,
            @Param("schoolid")String schoolid,
            @Param("classname")String classname
    ){
        TeacherDao teacherDao = new TeacherDao();
        teacherDao.setId(StringUtils.getSimpleUUID());
        teacherDao.setName(name);
        teacherDao.setSex(sex);
        teacherDao.setUsername(username);
        teacherDao.setPassword(password);
        teacherDao.setRole(2);
        teacherDao.setSchoolid(schoolid);
        teacherDao.setClassname(classname);
        return teacherService.addTeacher(teacherDao);
    }
}
